import Addition2 from '@/components/Addition2';
import {s_saveMaterialUserDefine, s_getMaterialCategoryTree, s_getMaterialDocument, s_getMaterialUserDefine, s_getOrgTargetKeysGlobal, s_getOrgTransferData, s_saveAllocateOrgGlobal, s_saveMaterialInfo, s_saveUnitData, getCommTreeByXid, status2text, s_getTableInfo, s_updateInfo, s_operateInfo, getFullTreeByXid } from '@/services/basis';
import { getSelection } from '@/services/selections';
import { ActionType, EditableFormInstance, EditableProTable, ProCard, ProColumns, ProForm, ProFormDatePicker, ProFormDigit, ProFormInstance, ProFormRadio, ProFormSelect, ProFormText, ProFormTextArea, ProTable } from '@ant-design/pro-components';
import { useModel, useRequest } from '@umijs/max';
import { Card, theme,Row,Col,Tree, Space, Button, Form, Input, Modal, Radio, Select, DatePicker, Drawer, Transfer, Divider, Checkbox, Tabs, TabsProps, message, Tag} from 'antd';
import Table, { ColumnsType } from 'antd/es/table';
import dayjs from 'dayjs';
import { Image } from 'antd';
import moment from 'moment';
import React, { useEffect, useRef, useState } from 'react';
import QueryMaterial2 from '@/components/QueryMaterial2';
import Addition from '@/components/Addition';
import _ from 'lodash';
import QueryUserDefine from '@/components/QueryUserDefine';
// import { useModel } from "@umijs/max";

//商品分类组件
 function CategoryTree(props:any){
  return(
    <Tree treeData={props.tdata}  
     defaultExpandAll={true} blockNode={true}
          onClick={(e,node)=>{props.getTreeInfo(node);}}/>
  );
}


//商品档案表组件-- 注意：table_ref用于外部控制表格还原
// function MaterialTable({tdata,setMaterialCode,table_ref}){
  function MaterialTable(props:any){
    const [selectedLineKeysm,setSelectedLineKeysm]=useState<any[]>([]);
  interface DataType{
    // x_id,cate_id,id,code,name,bom_id,invstd,invstd2,brand,status,
    // munit_name,pic,bom_version,bomtype,begindate,enddate,
    // saleorder_code,custom_id,custom_name,org_id,org_name,bom_memo,
    // bom_status,bom_state,verify_id,operater_id,
    // verify_name,bom_operater_name,bom_addition,
    r_id?:number,
    x_id?:number,cate_id?:number,id?:number,code?:string,name?:string,bom_id?:number,
    invstd?:string,invstd2?:string,brand?:string,status?:number,
    munit_name?:string,pic?:string,bom_version?:string,bomtype?:number,
    begindate?:string,enddate?:string,saleorder_code?:string,custom_id?:number,
    custom_name?:string,org_id?:number,org_name?:string,bom_memo?:string,
    bom_status?:number,bom_state?:string,verify_id?:number,operater_id?:number,
    verify_name?:string,bom_operater_name?:string,bom_addition:string,isdefault?:number, 
  }

   const columns:ProColumns<DataType>[]=[
    {dataIndex:'pic',title:'图片',width:60,
    //   render:(text)=>{
    //       var pic=text=="-"||text==undefined?"":"/basis_api/file/get?filename="+text;
    //          return <Image src={pic} style={{width:50,height:50}} alt='无' />
    //       },
    //  },
         render:(text,record,index,k)=>{
                           var pic="/basis_api/file/get2?filename="+record.code;
                           return   <Image src={pic}  style={{width:50,height:50}} alt='无' />
          } 
      },
     {dataIndex:'isdefault',hidden:true},{dataIndex:'bom_id',hidden:true},
     {dataIndex:'id',title:'商品ID',hidden:true},{dataIndex:'code',title:'SKU编码'},
     {dataIndex:'name',title:'商品名称'},{dataIndex:'invstd',title:'包装规格'},
    //  {dataIndex:'invstd2',title:'型号'},
     {dataIndex:'munit_name',title:'计量单位'},
    //  {dataIndex:'bom_version',title:'BOM版本'},
    //  {dataIndex:'bomtype',title:'BOM类型'},
     {dataIndex:'begindate',title:'生效日期',valueType:'date'},
     {dataIndex:'enddate',title:'失效日期',valueType:'date'},
    //  {dataIndex:'bom_memo',title:'备注'},
     {dataIndex:'bom_operater_name',title:'制单人'},
    //  {dataIndex:'verify_name',title:'审核人'},
     {dataIndex:'bom_status',title:'状态',
       render:(text:any)=>status2text(text),
     },
     
   ];

   return(
      <ProTable 
      dataSource={props.tdata} 
      columns={columns} 
      rowKey='rid' 
      rowSelection={{
          type:'radio',
          selectedRowKeys:selectedLineKeysm,
          onChange:(selectedKeys,selectedRows)=>{
            props.getBomDetail(selectedRows);
            setSelectedLineKeysm(selectedKeys);
          },
      }}
      onRow={(record)=>{
            return {
              onClick:()=>{
                const k=record.id;
                // if(selectedKeys.includes(k) )
                //      setSelectedKeys(selectedKeys.filter(item=>item.id!=k));
                // else
                     setSelectedLineKeysm([k]);
                     props.getBomDetail([record]);
              },
            }
           }}
      scroll={{y:'25vh'}}
      options={false}
      actionRef={props.table_ref}
      // pagination={{
      //   size:'small',
      //   pageSize:10,
      // }}
      pagination={false}
      search={false}
      
      />
     // onRow={(record)=>{return{onClick:()=>setMaterialCode(record.code)}}} />
   );

}
  
const Welcome: React.FC = () => {
  //选中的商品分类码。因需用于新增表单中，故{}
  const [selectedCategory,setSelectedCategory]=useState(0);       //选择的分类ID
  const [selectedCateNode,setSelectedNode]=useState<{title:string}>();            //选择的树节点
  const [treeData,setTreeData]=useState();                        //分类树数据源
  const [tdata,setTdata]=useState();                               //档案表格数据源
  const [selectedRecords,setSelectedRecords]=useState<DataType[]>([]);           //选中的商品编码,

  const [openInfo,setOpenInfo]=useState(false);//显示BOM窗口
  const [etype,setEtype]=useState(0);   //1新增 0修改
  const [bomDetail,setBomDetail]=useState<DataType2[]>([]);//主表单击后，调出BOM明细
  const [vouchCode,setVouchCode]=useState(null);//母件编辑+版本号，作为附件的依据

  const [selectedKeys,setSelectedKeys]=useState<any[]>([]);//树选择的本级节点及下节点
 
  const [addition,setAddition]=useState([]);

   //定义商品自由项
   const [udata,setUdata]=useState([]);//在表格中更新选择状态
   //定义计量单位 组件数据源
   const [uintSelection,setUintSelection]=useState([]);
   const [material,setMaterial]=useState([]);//查询商品组件结果
   const [userdefine,setUserDefine]=useState([]);//商品自由项
   const [rowno,setRowno]=useState(0);//商品自由项对应的可编辑表格ID
   const [bomid,setBomid]=useState<number>(0);//BOM保存后，返回的BOMID

   const formRef=useRef<ProFormInstance>();//商品编辑表单
   const table_ref=useRef<ActionType>();//用于向商品档案组件表传递引用
   const table_ref2=useRef<ActionType>();//BOM明细表引用
   const editorFormRef=useRef<EditableFormInstance>();//BOM明细编辑表
   const [expandKeys,setExpandKeys]=useState([]);
   const [trData,setTrData]=useState([]);

   const [selectedLineKeys,setSelectedLineKeys]=useState<any[]>([]);
   const [selectedLineKeys2,setSelectedLineKeys2]=useState<any[]>([]);
   const { initialState, setInitialState } = useModel('@@initialState');
    
   interface DataType{
    x_id?:number,cate_id?:number,id?:number,code?:string,name?:string,bom_id?:number,
    invstd?:string,invstd2?:string,brand?:string,status?:number,
    munit_name?:string,pic?:string,bom_version?:string,bomtype?:number,
    begindate?:string,enddate?:string,saleorder_code?:string,custom_id?:number,
    custom_name?:string,org_id?:number,org_name?:string,bom_memo?:string,
    bom_status?:number,bom_state?:string,verify_id?:number,operater_id?:number,
    verify_name?:string,bom_operater_name?:string,bom_addition:string,
  }
 //此处创建一个生成树的通用方法，通过传入表名和X_ID值
//  useRequest(()=>getCommTreeByXid({x_id:1,source_table:'material_category'}),{  
//   onSuccess:(data)=>{
//     setTreeData(data.ctree);
//     setExpandKeys(data.keys);
//   },
// });
useRequest(()=>getFullTreeByXid({x_id:1,treeType:'material_category'}),{
        onSuccess:(data)=>{
          setTrData(data.ctree);
          setExpandKeys(data.keys)
        },
    });

  //获取存货BOM档案表
 useRequest(()=>s_getMaterialDocument({x_id:1,cate_id:[],id:0,mtype:1}),{
         onSuccess:(data:any)=>{
          //  alert(JSON.stringify(data));
            setTdata(data[0]);
         },
     }
  );

//获取计量单位表
useRequest(()=>getSelection({source:'base_unit',code:'999'}),{
    onSuccess:(data:any)=>{
      const x=data.map((item:any)=>({value:item.code,label:item.name}));
      setUintSelection(x);
    }
});

//当组件选择商品时，更新表格并重载--------------
  useEffect(()=>{
               if(material.length>0){
               var x:any[]=editorFormRef.current?.getRowsData?.();
               // alert(JSON.stringify(x));
               if(x==undefined)
                  x=[];
               material.map((item:any)=>{
                  x?.push({rid:Math.random().toFixed(10),id:Math.random().toFixed(10).toString(),
                            material_id:item.id,code:item.code,name:item.name,
                            invstd:item.invstd,invstd2:item.invstd2,munit_name:item.munit_name,  
                            quantity_rate:'1/1', isbelongorder:1,
                            userdefine_id:'[]',pic:item.pic,
                  });
               });
               // alert(JSON.stringify(x));
              //  setDataSource(x);
                
               formRef.current?.setFieldValue('editortable',x);
               table_ref2.current?.reloadAndRest?.();
            }
            },[material]);

// 商品自由项编辑------------------
    useEffect(()=>{
              // if(userdefine.length>0){
                // alert(JSON.stringify(userdefine));
              const u=userdefine;
              var u1:any[]=[];
              var u2:any[]=[];
              u.map((item:any)=>{
                u1.push({uid:item.uid,value:item.value});
                u2.push(''.concat(item.uname,':',item.vlabel==''?item.value:item.vlabel));
              });
          
              // alert(JSON.stringify(u1));
              editorFormRef.current?.setRowData?.(rowno.toString(),{
                userdefine_id:JSON.stringify(u1) ,
                userdefine_name:u2.toString(),
              });
               
            // }
            },[userdefine]);
    
  //根据左侧选择的类别，右侧表格显示明细--注意：此处传入的是树节点node(key,title) 
  //---先取本节点及下级节点值，再共同选---------------------------------------------开始-----------------
  var arr:any[]=[];
   //定义一个递归函数，获取选中节点下的所有key
   function getNodeKeys(node:{key:any,title:any,children:any[]}){
        if(node.children.length>0)
              node.children.map((item:any)=>{
                 arr.push(item.key);
                 if(item.children.length>0){
                      arr.push(getNodeKeys(item));
                 }
             });
      }

  async function getMaterial(node:any){
     // alert( (curCategory));
      setSelectedRecords([]);
      setSelectedCategory(node.key);
      setSelectedNode(node);
     
     arr=[];//先置为空，再取数据
     arr.push(node.key);
     getNodeKeys(node);
     setSelectedKeys(arr.filter((item)=>item!=null));//当前选中的组织的所有下级ID

     const x=await s_getMaterialDocument({x_id:1,cate_id:arr,id:0,mtype:1});
     //alert(JSON.stringify(x.data[0]));
     setTdata(x.data[0]);
     table_ref.current?.reset?.();
  }
 //---先取本节点及下级节点值，再共同选---------------------------------------------结束-----------------


 interface DataType2{
  // id,mid,material_id,code,name,invstd,invstd2,
  // userdefine_id,userdefine_name,munit_name,
  // quantity_rate,isbelongorder,memo,status
  rid?:number,id?:number,mid?:number,material_id?:number,code?:string,name?:string,invstd?:string,
  invstd2?:string,userdefine_id?:string,userdefine_name?:string,pic?:string,
  munit_name?:string,quantity_rate?:string,isbelongorder?:number,memo?:string,status?:number
 }

 const columns2:ProColumns<DataType2>[]=[
  {dataIndex:'pic',title:'图片' ,editable:false,width:60,
//     render:(text)=>{
//         var pic=text=="-"||text==undefined?"":"/basis_api/file/get?filename="+text;
//         return <Image src={pic}  
//                style={{width:50,height:50}} alt='无' />
//    },
//  },
      render:(text,record,index,k)=>{
                       var pic="/basis_api/file/get2?filename="+record.code;
                       return   <Image src={pic}  style={{width:50,height:50}} alt='无' />
          } 
        },
  {dataIndex:'rid',title:'rid',hidden:true},{dataIndex:'id',title:'ID',hidden:true},
  {dataIndex:'code',title:'子件SKU编码',editable:false,},{dataIndex:'name',title:'商品名称',editable:false,},
  {dataIndex:'invstd',title:'包装规格',editable:false,},
  // {dataIndex:'invstd2',title:'型号',editable:false,},
  // {dataIndex:'userdefine_id',title:'UID',editable:false,},
  // {dataIndex:'userdefine_name',title:'属性',editable:false,},
  // {title:'设置',editable:false,
  //      render:(text,record)=><QueryUserDefine setData={setUserDefine} 
  //          objtype={1} dotype={1} id={record.material_id} setRowno={setRowno} rowno={record.rid} />
  //            },
  {dataIndex:'munit_name',title:'计量单位',editable:false,},
  {dataIndex:'quantity_rate',title:'母件/子件换算率',},
  // {dataIndex:'isbelongorder',title:'是否跟踪订单',
  //   valueType:'select',
  //   valueEnum:{
  //     0:{text:'否',status:'error'},
  //     1:{text:'是',status:'success'},
  //   }
  //   // render:(text)=>text==1?<Tag color='red' style={{width:66}}>是</Tag>:<>否</>,
  // },
    // {dataIndex:'memo',title:'备注'},
  {dataIndex:'status',title:'状态',hidden:true,
    render:(text:any)=>status2text(text),
  },
  {
    title:'操作',            
    fixed:'right',
    valueType:'option',
    width:80,
    editable:false,
    render:(text,record,_,action)=>[
      //  <a key='edit2'
      //     onClick={()=>{
      //         alert(record.rid);
      //        action?.startEditable?.(record.rid);}}
      //  >
      //      编辑
      //  </a>,
       <a  key='del2'
           onClick={()=>{
             var x:any[]=editorFormRef.current?.getRowsData?.()?editorFormRef.current?.getRowsData?.():[];
             //  alert(JSON.stringify(x));
               setBomDetail(x.filter((item)=>item.id!=record.id));
             // alert(JSON.stringify(x.filter((item)=>item.id!=record.id)));
             // mtable2_ref.current?.reloadAndRest?.();
             formRef.current?.setFieldValue('editortable',x.filter((item)=>item.rid!=record.rid));
           }}
       >
           删除
       </a>,
    ]
 }
 ];

 
  //编辑BOM信息
  async function editBomInfo(){
     if(selectedRecords.length===0)
         message.warning('请先选择要修改的商品。');
      else{
        setEtype(0);
          var bom_version='';
          var code='';
          var add=selectedRecords[0].bom_addition==undefined?[]:JSON.parse(selectedRecords[0].bom_addition);
          bom_version=selectedRecords[0].bom_version==undefined||selectedRecords[0].bom_version==''?'1':selectedRecords[0].bom_version;
          code=selectedRecords[0].code==undefined||selectedRecords[0].code==''?'1':selectedRecords[0].code;
          setVouchCode(code.concat('_',bom_version));
          // alert(JSON.stringify(code.concat('_',bom_version)));
        setAddition(add);
        setOpenInfo(true);
      };
  }

  //保存BOM信息
   async function saveBomInfo(){
          // 修改保存界面状态
          const x=editorFormRef?.current?.getRowsData?.();
          x?.map((item,index)=>{
              table_ref2.current?.saveEditable?.(index);
          });
          //获取表单数据
          const fdata2=formRef.current?.getFieldsValue();
          // const t1=fdata2.editortable;
          const fdata={...fdata2,
                       begindate:moment(moment(fdata2.begindate).toDate()).format('YYYY-MM-DD'),
                       enddate:moment(moment(fdata2.enddate).toDate()).format('YYYY-MM-DD'),
                       addition};
          
          //  alert(JSON.stringify(fdata));
                  // source,x_id,operater_id,etype,fdata
             const y=await s_updateInfo({x_id:1,source:'save_bom',operater_id:initialState?.currentUser?.userid,etype,fdata});
            // alert('dddd');
            // alert(JSON.stringify(y));
            if(y.success){
                    message.success('保存成功');
                    //返回保存后的ID值，作为审核引用
                    // alert(y.data[0]);
                    // setBomid(y.data[0][0].id);
                    formRef.current?.setFieldValue('bom_id',y.data[0][0].id);
                    formRef.current?.setFieldValue('bom_version',y.data[0][0].version);
                    // setEtype(1);
                    // setSelectedRecords([]);
                    // table_ref.current?.reloadAndRest?.();
                    // setOpen(false);
                    const x=await s_getMaterialDocument({x_id:1,cate_id:[],id:0,mtype:1});
                    setTdata(x.data[0]);
                    // table_ref.current?.reloadAndRest?.();
              }else
                    message.error('保存失败，请联系管理员');
          // setEtype(1);
          // setOpen(false);
      }

      //  审核与取消审核2025-03-15
            async function operateInfo(n:number,id:number){
             // source,x_id,operater_id,otype,id
             if(selectedRecords.length==0)
                message.warning('请选择要操作的行');
             else{
              const x=await s_operateInfo({x_id:1,source:'bom_main',operater_id:initialState?.currentUser?.userid,otype:n,id});
              if(x.success){
                message.success('操作成功');
                const x=await s_getMaterialDocument({x_id:1,cate_id:[],id:0,mtype:1});
                    setTdata(x.data[0]);
                  // table_ref.current?.reloadAndRest?.();
              }else
                message.error('操作错误，请联系管理员。');
             }
          }
  
  // 按BOM主表，查找子表明细
  async function getBomDetail(record:any){
     
      const x=await s_getTableInfo({source:'v_bom_detail',x_id:1,
                    id:record==undefined||record.length==0?0:record[0].bom_id});
        // alert('BOM主表记录：'+JSON.stringify(record));
      setSelectedRecords(record);
      //  alert(JSON.stringify(record[0].id));
       setBomid(record&&record.length>0?record[0].bom_id:0);
      setBomDetail(x.data);
  };

   // 全部开始编辑，置表格为编辑状态
                function quote(){
                  //用一个循环
                  const x:any[]=editorFormRef.current?.getRowsData?.();
                  if(x!=undefined&&x.length>0)
                    x.map((item:any,index)=>{
                        table_ref2.current?.startEditable?.(index);
                     }
                  );
                  else
                    message.warning('没有任何修改');
                }

//   主窗体=================================================================================
  return<>
     <Row gutter={10}>
     <Col  span={6}>
     <Card title='商品分类' style={{height:'85vh',overflow:'auto'}}>
         {/* <CategoryTree tdata={treeData} getTreeInfo={getMaterial}/> */}
         <Tree treeData={trData} expandedKeys={expandKeys} 
                  onExpand={(ekeys:any)=>setExpandKeys(ekeys)}
                   onClick={(e,node)=>getMaterial(node)}
                  />
     </Card>
     </Col>
     <Col  span={18}>
     <Card style={{height:'85vh',overflow:'auto'}}>
      <Card title='BOM主商品'  style={{height:'60%',overflow:'auto'}} id='drawer_id'
       
      extra={<Space size='large'>
      {/* <Button  onClick={()=>addBomInfo()}>新增BOM</Button> */}
      <Button  onClick={()=>editBomInfo()}>开始设置BOM</Button>
      <Button onClick={()=>operateInfo(5,bomid)}>审核</Button>
        <Button onClick={()=>operateInfo(6,bomid)}>取消审核</Button>
      {/* <Button  onClick={()=>allocateOrg()}>分配组织</Button> */}
      
      </Space>}
      >
      <MaterialTable tdata={tdata} getBomDetail={getBomDetail}  
           table_ref={table_ref}  />
      </Card>

      <ProCard title='BOM明细商品'  style={{height:'40%',overflow:'auto'}} id='drawer_id'>
             <ProTable<DataType2> 
                options={false}
                name='editortable'
                columns={columns2}
                rowKey='rid'
                dataSource={bomDetail}
                rowSelection={{
                  type:'radio'
                }}
                search={false}
                scroll={{y:200}}
             />
      </ProCard>
      </Card>
      </Col>
     </Row>

    
     <Modal open={openInfo}  width='80%'   maskClosable={false}  okButtonProps={{hidden:true}}
         destroyOnClose={true} closable={true} onCancel={()=>setOpenInfo(false)} cancelButtonProps={{hidden:true}}
     >  
       <ProCard title={etype==1?'新增BOM':'编辑BOM'} 
          style={{height:'80vh',overflow:'auto'}} 
          extra={<Space size='large'>
            <QueryMaterial2 setData={setMaterial} type='checkbox' x_id={1}/>
            <Addition source_xid={1} setData={setAddition} type={2}
                            fdata={{source_table:'addition_bom_main',
                                  source_code:vouchCode,
                                  source_field:'addition',
                                  source_id:selectedRecords.length==0?0:selectedRecords[0].bom_id,
                                  source_value:selectedRecords.length==0||selectedRecords[0].bom_addition==null||selectedRecords[0].bom_addition==''?[]:selectedRecords[0].bom_addition}}
                         />
            <Button onClick={()=>quote()}>开始编辑</Button>
            <Button onClick={()=>formRef.current?.submit()} >保存</Button>
            <Button onClick={()=>setOpenInfo(false)}>退出</Button>
          </Space>}  >
          {/* {JSON.stringify(selectedRecords)} */}
          <ProForm formRef={formRef} submitter={false} labelAlign='left' layout='horizontal' 
          labelCol={{offset:0,span:8}}
          initialValues={selectedRecords.length>0&&selectedRecords[0].bom_version!=undefined?{
              ...selectedRecords[0],
               editortable:bomDetail,
          }:{
               ...selectedRecords[0],
              //  editortable:bomDetail,
              bom_version:1,
              bomtype:1,
              isbelongorder:1,
              begindate:moment().format('YYYY-MM-DD'),
              enddate:"2099-12-31",
              bom_state:1,
              bom_status:0, 
              operater_id:initialState?.currentUser?.userid,
          }}
          onFinish={()=>saveBomInfo()}
          >
          <Row gutter={8}>
            <ProFormText name='id' hidden={true}/><ProFormText name='bom_id' hidden={true}/>
            <ProFormText name='verify_id' hidden={true} />
            <Col span={6}>
                <ProFormText name='code' label='母件编码' width={200}
                  fieldProps={{
                      onChange:(e:any)=>{
                      var code=e.target.value;
                      var ver=formRef.current?.getFieldValue('bom_version');
                      if(ver==undefined||ver==''||code==undefined||code=='')
                         setVouchCode(null);
                      else
                         setVouchCode(code.concat('_',ver));
                      // alert('BOM单据号：'+vouchCode);
                   // mform_ref.current?.setFieldValue('addition',e.target.value);
                  }
                  }}
                />
                <ProFormText name='name' label='名称' width={200}/>
                <ProFormText name='invstd' label='包装规格' width={200}/>
                <ProFormText name='munit_name' label='计量单位' width={200}/>
            </Col>
            <Col span={6}>
                 <ProFormText name='bom_version' label='BOM版本' width={200}
                  rules={[{required:true,message:'必输项'}]}
                   fieldProps={{
                    onChange:(e:any)=>{
                    var ver=e.target.value;
                    var code=formRef.current?.getFieldValue('code');
                    if(ver==undefined||ver==''||code==undefined||code=='')
                       setVouchCode(null);
                    else
                       setVouchCode(code.concat('_',ver));
                    // alert('BOM单据号：'+vouchCode);
                 // mform_ref.current?.setFieldValue('addition',e.target.value);
                }
                }}
                 
                 />
                 <ProFormRadio.Group name='bomtype' label='BOM类型' width={200}
                    rules={[{required:true,message:'必输项'}]}
                    options={[{value:1,label:'标准'},{value:2,label:'订单'},{value:3,label:'客户'}]}
                 />
                 <ProFormSelect name='custom_id' label='专用客户' width={200}
                      fieldProps={{
                        showSearch:true,
                       }}
                       request={async ()=>{
                        var x:any=await getSelection({source: 'v_custom', x_id: 1 });
                        var x2=x.data.map((item:any)=>({value:item.id,label:item.name}));
                        return x2;
                        }}
                 />
                 <ProFormText name='saleorder_code' label='专用订单号' width={200}/>
            </Col>
            <Col span={6}>
                 {/* <ProFormRadio.Group name='isbelongorder' label='子件跟踪订单' width={200}
                    // rules={[{required:true,message:'必输项'}]}
                    options={[{value:0,label:'否'},{value:1,label:'是'}]}
                 /> */}
                 <ProFormDatePicker name='begindate' label='生效日期' width={200}
                      rules={[{required:true,message:'必输项'}]}
                 />
                 <ProFormDatePicker name='enddate' label='失效日期' width={200}
                      rules={[{required:true,message:'必输项'}]}
                 />
                 <ProFormSelect name='verify_id' label='审核人' width={200}
                  fieldProps={{
                    showSearch:true,
                   }}
                   request={async ()=>{
                    var x:any=await getSelection({source: 'base_person', x_id: 1 });
                    var x2=x.data.map((item:any)=>({value:item.id,label:item.name}));
                    return x2;
                    }}
                 />
                 <ProFormTextArea name='bom_memo' label='备注' width={200}/>
            </Col>
            <Col span={6}>
                 <ProFormSelect name='operater_id' label='制单人' width={200}
                   fieldProps={{
                     showSearch:true,
                    }}
                    request={async ()=>{
                      var x:any=await getSelection({source: 'base_person', x_id: 1 });
                      var x2=x.data.map((item:any)=>({value:item.id,label:item.name}));
                      return x2;
                    }}    
                 />
                 <ProFormSelect name='org_id' label='制单部门' width={200}
                  fieldProps={{
                    showSearch:true,
                   }}
                   request={async ()=>{
                    var x:any=await getSelection({source: 'base_organization', x_id: 1 });
                    var x2=x.data.map((item:any)=>({value:item.id,label:item.name}));
                    return x2;
                    }}
                 />
                 {/* <ProFormSelect name='bom_state' label='进度' width={200}
                   options={[{value:1,label:'未下达'},{value:2,label:'已下达'},{value:3,label:'供方已确认'},{value:4,label:'供方已拒绝'},
                     {value:5,label:'已确认'},{value:6,label:'已拒绝'},{value:7,label:'撤销确认'},{value:8,label:'供方撤销确认'},
                     {value:9,label:'撤销下达'},{value:10,label:'未提交'},{value:11,label:'已提交'},{value:12,label:'撤销提交'},
                     {value:13,label:'已核价'},{value:14,label:'撤销核价'}
                 ]}
                 /> */}
                 <ProFormRadio.Group name='isdefault' label='是否默认' 
                     rules={[{required:true,message:'此为必填项'}]}
                     options={[{value:0,label:'否'},{value:1,label:'是'}]}
                 />
                 <ProFormRadio.Group name='bom_status' label='状态' width={200}
                     rules={[{required:true,message:'此为必填项'}]}
                     options={[{value:0,label:'未审核'},{value:2,label:'冻结'},
                          {value:5,label:'已审核'},{value:6,label:'弃审'},
                          {value:3,label:'删除'}]}
                 />
                 <ProFormText name='bom_id' label='BOMID'/>
            </Col>
          </Row>
          <ProCard style={{height:'50vh',overflow:'auto'}}>
          <EditableProTable<DataType2>
              editableFormRef={editorFormRef}
              actionRef={table_ref2}
              name='editortable'
              columns={columns2}
              rowKey='rid'
              dataSource={bomDetail}
               editable={{
                type:'multiple',
               }}
             search={false}
             recordCreatorProps={false}
             scroll={{y:390}}
             options={false}
             />
             </ProCard>
        </ProForm>
       </ProCard>  
     </Modal>

     
  </>
};

export default Welcome;


